package com.saa.dict.controller;


import com.saa.application.po.SaaApplicationInfo;
import com.saa.common.vo.OmsResultVo;
import com.saa.dict.service.SaaDictService;
import com.saa.dict.vo.DictDetail;
import com.saa.dict.vo.SaaDictVo;
import com.saa.dict.vo.SaaRiskVo;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Map;

@RestController
@RequestMapping(value = "/saa/dict")
public class SaaDictController {
    private Logger logger = LoggerFactory.getLogger(SaaDictController.class);
    @Autowired
    private SaaDictService saaDictService;

    /****根据应用、类型、状态分页查询数据字典***/
    @PostMapping("/getSaaDictListByParams")
    public OmsResultVo getSaaDictListByParams(@RequestBody Map<String,Object> paramMap) {
        if(!paramMap.isEmpty()){
            return saaDictService.findSaaDictListByParams(paramMap);
        }else{
            return OmsResultVo.builder(500, "请求数据为空", null);
        }
    }

    /****批量保存或修改数据字典信息***/
    @PostMapping("saveDictList")
    public OmsResultVo saveDictList(@RequestBody DictDetail dictDetail){
        return saaDictService.saveSaaDictList(dictDetail);
    }

    /****根据应用查询数据字典类型列表***/
    @PostMapping("/getDistInfoByAppCode")
    public OmsResultVo getDistInfoByAppCode(@RequestBody Map<String,Object> paramMap) {
        return saaDictService.findDistInfoByAppCode(paramMap);
    }

    /****根据类型id查询字典详情包括字典数据列表***/
    @PostMapping("/getDistInfo")
    public OmsResultVo getDistInfo(@RequestBody Map<String,Object> paramMap) {
        String dictId = (String)paramMap.get("dictId");
        return OmsResultVo.builder(200, "查询成功", saaDictService.getSaaDictVo(dictId));
    }

    /****保存单条数据字典信息***/
    @PostMapping("/saveDistInfo")
    public OmsResultVo saveDistInfo(@RequestBody SaaDictVo saaDictVo) {
        return saaDictService.saveSaaDict(saaDictVo);
    }

    /****删除数据字典***/
    @PostMapping("/deleteDistInfo")
    public OmsResultVo deleteDistInfo(@RequestBody Map<String,Object> paramMap) {
        return saaDictService.deleteDist(paramMap);
    }

    /****修改单条数据字典信息***/
    @PostMapping("/updateDistInfo")
    public OmsResultVo updateDistInfo(@RequestBody SaaDictVo saaDictVo) {
        return saaDictService.updateSaaDict(saaDictVo);
    }

    /****根据应用、类型查询数据字典类型列表***/
    @PostMapping("getDistsByConditon")
    public OmsResultVo getDistsByConditon(Map<String,Object> paramMap){
        return saaDictService.findDistsByConditon(paramMap);
    }

    /****查询保险产品数据列表***/
    @PostMapping("/getClassList")
    public OmsResultVo getClassList() {
        return OmsResultVo.builder(200, "新增成功", saaDictService.getClassList());
    }

    /***根据险类代码查询险种***/
    @PostMapping("/getRiskList")
    public OmsResultVo getRiskList(@RequestBody SaaRiskVo saaRiskVo) {
        return OmsResultVo.builder(200, "新增成功", saaDictService.getRiskList(saaRiskVo));
    }

    /*****获取数据类型列表***/
    @PostMapping("/getCodeType")
    public OmsResultVo getCodeType(@RequestBody List<SaaDictVo> saaDictVos){
        return OmsResultVo.builder(200, "新增成功", saaDictService.getCodeType(saaDictVos));
    }

    /*****根据数据类型获取数据列表***/
    @PostMapping("/getDistList")
    public OmsResultVo getDistList(@RequestBody SaaDictVo saaDictVo){
        return OmsResultVo.builder(200, "新增成功", saaDictService.getDistList(saaDictVo));
    }
}
